//
//  KLComposeCell.m
//  KL
//
//  Created by mac on 15/12/21.
//  Copyright © 2015年 zhouxubin. All rights reserved.
//

#import "KLComposeCell.h"
#import <UIImageView+WebCache.h>
#import "KLCompose.h"

@interface KLComposeCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *webSiteLabel;

@end

@implementation KLComposeCell

#pragma mark - 重写setter方法给属性赋值
- (void)setCompose:(KLCompose *)compose {
    _compose = compose;
#warning 图片的占位图片,学校网速不好,待会回去记得搜一下
    // 图片
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:compose.sppic] placeholderImage:[UIImage imageNamed:@""] options:SDWebImageProgressiveDownload];
    
    // 商品名字
    self.nameLabel.text = compose.spname;
    
    // 商品价格
    self.priceLabel.text = [NSString stringWithFormat:@"%@的价格: ￥%@", compose.siteName, compose.spprice];
    
    // 网址
    self.webSiteLabel.text = compose.spurl;
}

#pragma mark - 初始化方法
+ (instancetype)composeCellWith:(UITableView *)tableView {
    static NSString *ID = @"compose_cell";
    KLComposeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [self composeCell];
    }
    return cell;
}

+ (instancetype)composeCell {
    return [[[NSBundle mainBundle] loadNibNamed:@"KLComposeCell" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
